package com.fjut.controller;


import com.fjut.model.wechat.Menu;
import com.fjut.result.Result;
import com.fjut.service.MenuService;
import com.fjut.vo.wechat.MenuVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 订单明细 订单明细 前端控制器
 * </p>
 *
 * @author DengTianxun
 * @since 2023-03-10
 */
@Api(tags = "公众号订单接口")
@RestController
@RequestMapping("/fjut/wechat/menu")
public class MenuController {

    @Autowired
    private MenuService menuService;

    @ApiOperation("获取菜单")
    @GetMapping("getMenuList/{id}")
    public Result getMenuList(@PathVariable Long id){
        return Result.success(menuService.getById(id));
    }

    @ApiOperation("更新菜单")
    @PostMapping("updateMenu")
    public Result updateMenu(@RequestBody Menu menu){
        return Result.success(menuService.updateById(menu));
    }

    @ApiOperation("新增菜单")
    @PostMapping("saveMenu")
    public Result saveMenu(@RequestBody Menu menu){
        return Result.success(menuService.save(menu));
    }

    @ApiOperation("删除菜单")
    @DeleteMapping("deleteMenuById/{id}")
    public Result deleteMenuById(@PathVariable Long id){
        return Result.success(menuService.removeById(id)).message("删除成功");
    }

    @ApiOperation("删除菜单列表")
    @DeleteMapping("deleteMenuList")
    public Result deleteMenuList(@RequestBody List<Long> idList){
        return Result.success(menuService.removeByIds(idList)).message("删除成功");
    }

    @ApiOperation("获取所有一级菜单")
    @GetMapping("getMenuTreeList")
    public Result getMenuTreeList(){
        return Result.success(menuService.getMenuTreeList());
    }

    @ApiOperation("获取菜单树形结构")
    @GetMapping("getMenuAllTreeList")
    public Result getMenuAllTreeList(){
        return Result.success(menuService.getMenuAllTreeList());
    }

    @ApiOperation("获取access_token")
    @GetMapping("getAccessToken")
    public Result getAccessToken(){
        return Result.success(menuService.getAccessToken());
    }

    @ApiOperation("同步服务器菜单")
    @GetMapping("syncMenu")
    public Result syncMenu(){
        return Result.success(menuService.syncMenu());
    }

    @ApiOperation("删除公众号菜单")
    @DeleteMapping("removeMenu")
    public Result removeMenu(){
        return Result.success(menuService.removeMenu());
    }
}

